using System;
using System.Collections.Generic;
using System.Text;

namespace Utils.Model
{
    public class Holder<T> : Element
    {
        public Holder() 
        { 

        }

        public T this[int index] 
        {
            get { return list[index];  }
            set { list[index] = value; }
        }

        public T this[int index, T defValue]
        {
            get { return index >= 0 && index < list.Count ? list[index] : defValue; }
        }

        public int Count 
        {
            get { return list.Count; }
        }

        public bool HasNext
        {
            get { return cursor < list.Count; }
        }

        public void MoveNext() 
        {
            cursor++;
        }

        public T Current(T defValue) 
        {
            if (cursor < list.Count)
            { 
                return list[cursor]; 
            }

            return defValue;
        }

        public T Current()
        {
            return list[cursor];
        }

        public void Reset()
        {
            cursor = 0;
        }

        public T Front()
        {
            return list[0];
        }

        public T Back()
        {
            return list[list.Count - 1]; 
        }

        public T Front(T defValue)
        {
            if ( list.Count > 0 )
            {
                return list[0];
            }

            return defValue;
        }

        public T Back(T defValue)
        {
            if (list.Count > 0)
            {
                return list[list.Count - 1];
            }

            return defValue;
        }

        public void AddBack(T obj)
        {
            list.Add(obj);
        }

        public void AddFront(T obj)
        {
            list.Insert(0,obj);
        }

        internal List<T> list = new List<T>();
        internal int cursor = 0;
    }
}
